# Contributor:
# Maintainer:
pkgname=rpm
pkgver=4.16.1.3
pkgrel=3
pkgdesc="Redhat Package Management utilities (RPM)"
url="https://rpm.org/"
arch="all"
license="GPL-2.0-or-later LGPL-2.0-or-later"
depends_dev="acl-dev binutils-dev bzip2-dev sqlite-dev file-dev libarchive-dev
	libcap-dev libgcrypt-dev popt-dev xz-dev zlib-dev"
makedepends="$depends_dev gettext-dev graphviz py3-setuptools python3-dev
	zstd-dev automake autoconf libtool"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang py3-rpm:py_rpm"
source="http://ftp.rpm.org/releases/rpm-${pkgver%.*.*}.x/rpm-$pkgver.tar.bz2
	musl.patch
	"

# secfixes:
#   4.16.1.3-r0:
#     - CVE-2021-3421
#     - CVE-2021-20271
#     - CVE-2021-20266

prepare() {
	# Switch to sqlite db by default, including during build-time tests
	sed -i -e "/_db_backend/ s/ bdb/ sqlite/g" macros.in

	default_prepare
	autoreconf -fi
}

build() {
	LIBS="$LIBS -lintl" \
	PYTHON=python3 \
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--with-cap \
		--with-acl \
		--without-lua \
		--enable-python \
		--enable-zstd=yes \
		--enable-sqlite=yes \
		--enable-bdb_ro=yes \
		--enable-bdb=no \
		--with-crypto=libgcrypt \
		--disable-plugins
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

py_rpm() {
	pkgdesc="Python3 bindings for RPM"

	replaces="py-rpm" # Backwards compatibility
	provides="py-rpm=$pkgver-r$pkgrel" # Backwards compatibility

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/python* "$subpkgdir"/usr/lib
}

sha512sums="54e503b32dffaa73d6168f26a00220d9d9124082d8a1eb1ddf34ce32a482f07cb06ec654cf065fca1607cc37b13fa7d4fa9895553541d7cfddecf68c9eb96f2e  rpm-4.16.1.3.tar.bz2
212a4265abc8d002e16bed106b8b773cf65564f95e6074bc1378c4745420202a476373b49b660bdfe82cc2470c35fff4f184168a698abfa2a4bf30c8f91e64ad  musl.patch"
